package com.algorithms;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

import twitter4j.User;

public class Document {

	private List<PonderatedWord> document;
	private int index = 0;

	private User user;

	public Document() {
		this.document = new ArrayList<PonderatedWord>();
	}

	public Document(List<PonderatedWord> document) {
		this.document = document;
	}

	public Document(List<PonderatedWord> document, User user) {
		super();
		this.document = document;
		this.user = user;
	}

	public PonderatedWord getNextWord() {
		return document.get(index++);
	}

	public void reset() {
		index = 0;
	}

	public void add(String word) {
		document.add(new PonderatedWord(word, -1));
	}

	public void add(PonderatedWord word) {
		document.add(word);
	}

	public void modifyWeight(double weight) {
		document.get(index).setWeight(weight);
	}

	public void addAll(Collection<? extends PonderatedWord> collection) {
		document.addAll(collection);
	}

	public void addAllStrings(Collection<String> collection) {
		for (String word : collection)
			this.add(word);
	}

	public int size() {
		return this.document.size();
	}

	public boolean hasNext() {
		return index < document.size();
	}

	public double getWeight(String word) {

		for (PonderatedWord pWord : document)
			if (word.equals(pWord.getWord())) return pWord.getWeight();

		return 0;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}
}